// pages/recycle/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    cate:1,
    tabCur: 0, //默认选中
    cate_list:[{id:1,title:'分类一'},{id:2,title:'分类二'},{id:3,title:'分类三'},{id:4,title:'分类四'},{id:5,title:'分类五'},{id:6,title:'分类六'}],
    tabs: [{
        name: '饮品',
        id: 0
      },
      {
        name: '配件',
        id: 1
      },
      {
        name: '黄金',
        id: 2
      },
      {
        name: '苹果',
        id: 3
      },
      {
        name: '小米',
        id: 4
      },
      {
        name: '华为',
        id: 5
      },
      {
        name: '荣耀',
        id: 6
      }
    ],

    lists:[{
      id:1,name:'二级分类名称占位',selected:false,count:6,selected_count:0,
      child:[{
        id:11,name:'二级分类名称占位',
        child:[{id:111,name:'二级分类名称占位',selected:false,pid:1},{id:112,name:'二级分类名称占位',selected:false,pid:1},{id:113,name:'二级分类名称占位',selected:false,pid:1}]
      },{
        id:12,name:'二级分类名称占位',
        child:[{id:121,name:'二级分类名称占位',selected:false,pid:1},{id:122,name:'二级分类名称占位',selected:false,pid:1},{id:123,name:'二级分类名称占位',selected:false,pid:1}]
      }]
    },{
      id:2,name:'二级分类名称占位',selected:false,count:6,selected_count:0,
      child:[{
        id:21,name:'二级分类名称占位',
        child:[{id:211,name:'二级分类名称占位',selected:false,pid:2},{id:212,name:'二级分类名称占位',selected:false,pid:2},{id:213,name:'二级分类名称占位',selected:false,pid:2}]
      },{
        id:22,name:'二级分类名称占位',
        child:[{id:221,name:'二级分类名称占位',selected:false,pid:2},{id:222,name:'二级分类名称占位',selected:false,pid:2},{id:223,name:'二级分类名称占位',selected:false,pid:2}]
      }]
    }]

  },

  selectList2(e){
    var id = e.currentTarget.dataset.id
    var lists = this.data.lists
    for(var i=0;i<lists.length;i++){
      for(var j=0;j<lists[i]['child'].length;j++){
        for(var z=0;z<lists[i]['child'][j]['child'].length;z++){
          if(lists[i]['child'][j]['child'][z]['id']==id){
            if(lists[i]['child'][j]['child'][z]['selected'] == true){
              lists[i]['child'][j]['child'][z]['selected'] = false
            }else{
              lists[i]['child'][j]['child'][z]['selected'] = true
            }
          }
        }
      }
    }

    for(var i=0;i<lists.length;i++){
      lists[i]['selected_count'] = 0
      for(var j=0;j<lists[i]['child'].length;j++){
        for(var z=0;z<lists[i]['child'][j]['child'].length;z++){
          if(lists[i]['child'][j]['child'][z]['selected'] == true){
            lists[i]['selected_count'] +=1
          }
        }
      }
      if(lists[i]['selected_count']==lists[i]['count']){
        lists[i]['selected'] = true
      }else{
        lists[i]['selected'] = false
      }
    }

    this.setData({
      lists:lists
    })
  },

  change(e){
    this.setData({
      cate:e.currentTarget.dataset.id
    })
  },

  selectList(e){
    var id = e.currentTarget.dataset.id
    var lists = this.data.lists
    for(var i=0;i<lists.length;i++){
      for(var j=0;j<lists[i]['child'].length;j++){
        for(var z=0;z<lists[i]['child'][j]['child'].length;z++){
          if(lists[i]['child'][j]['child'][z]['pid']==id){
            if(lists[i]['selected'] == true){
              lists[i]['child'][j]['child'][z]['selected'] = false
            }else{
              lists[i]['child'][j]['child'][z]['selected'] = true
            }
          }
        }
      }

      if(lists[i]['id']==id){
        if(lists[i]['selected'] == true){
          lists[i]['selected'] = false
        }else{
          lists[i]['selected'] = true
        }
      }
    }

    this.setData({
      lists:lists
    })
  },

  price(){
    wx.navigateTo({
      url: '/pages/recycle/price',
    })
  },

   //选择条目
   tabSelect(e) {
    this.setData({
      tabCur: e.currentTarget.dataset.id,
      scrollLeft: (e.currentTarget.dataset.id - 2) * 200
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})